package edu.whu.proxy;

import edu.whu.dao.UserDao;
import edu.whu.dao.impl.UserDaoImpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;


public class LogHandler implements InvocationHandler {
    Object target; // 被拦截的对象

    public LogHandler(Object target){
        this.target=target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String info= "进入"+method.getName()+"方法,";
        info +="参数是：";
        for (Object arg : args) {
            info+= arg+" ";
        }
        System.out.println(info);
        //调用目标对象的方法
        return method.invoke(target,args);
    }

}
